package org.common.utils.database.entity;
import org.common.utils.database.mapper.AbstractMapper;
import java.util.List;

public class AdventureMedalMapper extends AbstractMapper<AdventureMedal> {

    private static final String INSERT_TEMPLATE = "insert into `adventure_medal` (`id`, `MedalType`, `Name`, `Medal_stats`, `property_range_type`, `all_atk`, `all_hp`, `key`) values (?, ?, ?, ?, ?, ?, ?, ?)";

    private static final String UPDATE_TEMPLATE  = "update `adventure_medal` set `id` = ?, `MedalType` = ?, `Name` = ?, `Medal_stats` = ?, `property_range_type` = ?, `all_atk` = ?, `all_hp` = ?, `key` = ? where `id` = ?";

    private static final String DELETE_TEMPLATE  = "delete from `adventure_medal` where `id` = ?";

    private static final String SELECT_TEMPLATE = "select `id`, `MedalType`, `Name`, `Medal_stats`, `property_range_type`, `all_atk`, `all_hp`, `key` from `adventure_medal` where ";

    @Override
    public List<AdventureMedal> select(String whereString , List<Object> params) {
        return executeList(SELECT_TEMPLATE , whereString , params, (resultSet -> {
            AdventureMedal object = new AdventureMedal();
            object.setId(resultSet.getInt(1));
            object.setMedalType(resultSet.getInt(2));
            object.setName(resultSet.getString(3));
            object.setMedalStats(resultSet.getString(4));
            object.setPropertyRangeType(resultSet.getInt(5));
            object.setAllAtk(resultSet.getInt(6));
            object.setAllHp(resultSet.getInt(7));
            object.setKey(resultSet.getInt(8));
            return object;
        }));
    }

    @Override
    public int insert(AdventureMedal object) {
        return insert(List.of(object))[0];
    }

    @Override
    public int[] insert(List<AdventureMedal> list) {
        return executeBatch(INSERT_TEMPLATE , list , (preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
            preparedStatement.setObject(2 , object.getMedalType());
            preparedStatement.setObject(3 , object.getName());
            preparedStatement.setObject(4 , object.getMedalStats());
            preparedStatement.setObject(5 , object.getPropertyRangeType());
            preparedStatement.setObject(6 , object.getAllAtk());
            preparedStatement.setObject(7 , object.getAllHp());
            preparedStatement.setObject(8 , object.getKey());
        });
    }

    @Override
    public int update(AdventureMedal object) {
        return update(List.of(object))[0];
    }

    @Override
    public int[] update(List<AdventureMedal> list) {
        return executeBatch(UPDATE_TEMPLATE , list , (preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
            preparedStatement.setObject(2 , object.getMedalType());
            preparedStatement.setObject(3 , object.getName());
            preparedStatement.setObject(4 , object.getMedalStats());
            preparedStatement.setObject(5 , object.getPropertyRangeType());
            preparedStatement.setObject(6 , object.getAllAtk());
            preparedStatement.setObject(7 , object.getAllHp());
            preparedStatement.setObject(8 , object.getKey());
            preparedStatement.setObject(9 , object.getId());
        });
    }

    @Override
    public int delete(AdventureMedal object) {
        return delete(List.of(object))[0];
    }

    @Override
    public int[] delete(List<AdventureMedal> list) {
        return executeBatch(DELETE_TEMPLATE , list , ((preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
        }));
    }
}
